package com.dingreading.cloud.mall.service.impl;

import com.dingreading.cloud.mall.entity.StoreGoodsDiscount;
import com.dingreading.cloud.mall.entity.table.StoreGoodsDiscountTableDef;
import com.dingreading.cloud.mall.mapper.StoreGoodsDiscountMapper;
import com.dingreading.cloud.mall.service.StoreGoodsDiscountService;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2025-07-24
 */
@Service
public class StoreGoodsDiscountServiceImpl extends BaseServiceImpl<StoreGoodsDiscountMapper, StoreGoodsDiscount, StoreGoodsDiscountTableDef> implements StoreGoodsDiscountService {

    @Override
    protected StoreGoodsDiscountTableDef getTable() {
        return StoreGoodsDiscountTableDef.storeGoodsDiscount;
    }

    @Override
    public StoreGoodsDiscount getEnabledDiscount(String storeUid) {
        return getMapper().selectOneByCondition(table.storeUid.eq(storeUid).and(table.enabled.eq(1)));
    }

    @Override
    public Double getDiscountRate(String storeUid) {
        QueryWrapper wrapper = QueryWrapper.create()
                .select(table.discountRate)
                .from(table)
                .where(table.storeUid.eq(storeUid).and(table.enabled.eq(1)));
        return getMapper().selectObjectByQueryAs(wrapper, Double.class);
    }
}
